package com.hiedu.service.impl;

import com.hiedu.beans.entity.OrderItem;
import com.hiedu.beans.entity.Product;
import com.hiedu.beans.vo.ProductVO;
import com.hiedu.mapper.OrderItemMapper;
import com.hiedu.service.OrderItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ProjectName: hi-app
 * @Titile: OrderItemServiceImpl
 * @Author: Lucky
 * @Description: 订单项业务实现类
 */
@Service //代表是业务
public class OrderItemServiceImpl implements OrderItemService {
    @Autowired
    private OrderItemMapper orderItemMapper;

    @Override
    public ProductVO getProductById(Integer id) {
        //根据订单项id去查询订单项数据
        OrderItem orderItem = orderItemMapper.getById(id);
        if(orderItem == null){
            throw new RuntimeException("该订单项编号不存在");
        }

        // todo 判断订单项编号的合法性
        Product product = orderItemMapper.getProductById(id);
        if(product == null){
            throw new RuntimeException("该订单项编号有误，没有商品");
        }
        //封装VO
        ProductVO productVO = new ProductVO();
        productVO.setId(product.getId());
        productVO.setName(product.getName());
        productVO.setPrice(product.getPrice());
        productVO.setNum(product.getNum());
        productVO.setCreateTime(product.getCreateTime());
        return productVO;
    }

}
